package thread;

import java.util.concurrent.*;

/**
 * @Description: 作用描述
 * @Author: hmm
 * @CreateDate: 2019/7/30$ 23:38$
 * @UpdateUser: hmm
 * @UpdateDate: 2019/7/30$ 23:38$
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
public class Demo4 {

    public static void excute() {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10, 10, 30, TimeUnit.SECONDS,
                new LinkedBlockingDeque<Runnable>(), Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        threadPoolExecutor.execute(() ->
                printNum()
        );
        threadPoolExecutor.execute(() ->
                printNum()
        );
        System.out.println("主线程" + Thread.currentThread().getName());
        threadPoolExecutor.shutdown();
    }

    private static void printNum() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
                System.out.println(Thread.currentThread().getName() + "--------" + i);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {

        Demo4.excute();
    }
}
